using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace HybridCLR.Extension.Editor
{
    public  partial class Commond
    {
        public static void CopyAddressableFileToPath(BuildParam buildParam)
        {
            if (buildParam.Result == BuildResult.Building)
            {
                CopyAddressableFileToPath(System.IO.Path.GetDirectoryName(buildParam.AddressableAssetBuildResult.OutputPath), buildParam.CopyAddressableFileToPath);
            }
        }
        public static void CopyAddressableFileToPath()
        {
            string copyPath = System.IO.Path.GetDirectoryName(UnityEditor.AddressableAssets.AddressableAssetSettingsDefaultObject.Settings.buildSettings.bundleBuildPath);
            CopyAddressableFileToPath(copyPath);
        }
        public static void CopyAddressableFileToPath(string copyPath, string copyToPath = "HybridCLRDataBuild")
        {
            string[] files = System.IO.Directory.GetFiles(copyPath, "*", searchOption: System.IO.SearchOption.AllDirectories);
            string log = "";
            foreach (var file in files)
            {
                string internalPath = file.Replace(copyPath, "");
                string targetPath = copyToPath + internalPath;
                if(!System.IO.Directory.Exists(targetPath))
                    System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(targetPath));
                System.IO.File.Copy(file, targetPath, true);
                log += $"{file} copied to {targetPath}\n";
            }
            GLog.Log($"移动资源 {log}");
        }
    }
}
